//
//  DHChooseDiseaseViewController.m
//  DHKuaiYi
//
//  Created by  chenhanmao on 2016/11/13.
//  Copyright © 2016年 30-陈辉华. All rights reserved.
//

#import "DHChooseDiseaseViewController.h"
#import <Masonry.h>
#import "DHArrowTableViewCell.h"
#import "DHSelectTableViewCell.h"
#import "UIColor+XHHAddition.h"
#import "DHDoctorApplyViewController.h"


static NSString *arrowCellID = @"arrowCell";
static NSString *selectCellID = @"selectCell";
@interface DHChooseDiseaseViewController ()<UITableViewDataSource,UITableViewDelegate>

/**  tableView  */
@property(nonatomic,weak) UITableView *tableView;

/**   是否接受过治疗  */
@property(nonatomic,assign) BOOL isTreated;

@end

@implementation DHChooseDiseaseViewController

- (void)xhhSetupNavigationItems {
    
    [super xhhSetupNavigationItems];
    
    self.title = @"疾病详情选择";
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"预约须知" style:UIBarButtonItemStylePlain target:self action:@selector(beSpokenNotice)];
    
    self.navigationItem.rightBarButtonItem = rightBtn;
    
}

- (void)beSpokenNotice {
    
    NSLog(@"预约须知");
}


#pragma mark - dataSource方法的实现
//  返回组数
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 5;
}

//  返回行数
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

//  返回cell
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *cellID;
    
    if (indexPath.section == 2 || indexPath.section == 3) {
        cellID = selectCellID;
       
    }else{
        cellID = arrowCellID;
    }
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    if (indexPath.section == 1) {
         DHArrowTableViewCell *selectedCell = (DHArrowTableViewCell *)cell;
        selectedCell.text = @"请选择并发症";
    }
    if (indexPath.section == 4) {
        DHArrowTableViewCell *selectedCell = (DHArrowTableViewCell *)cell;
        selectedCell.text = @"请选择选择治疗方式";
    }
    
    if (indexPath.section == 3) {
        DHSelectTableViewCell *selectedCell = (DHSelectTableViewCell *)cell;
        //处理block的循环引用
        __weak typeof(self) weakSelf = self;
        
        selectedCell.labelText = @"是否接受过治疗";
        selectedCell.isText = @"接受过";
        selectedCell.noText = @"未接受过";
        selectedCell.selectedBlock = ^(BOOL isTreated){
            weakSelf.isTreated = isTreated;
        };
    }
    
    return cell;
}


#pragma mark - UITableViewDelegate
//组间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 4;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //初始化界面是隐藏治疗方法
    NSIndexPath *tmpPath = [NSIndexPath indexPathForRow:0 inSection:4];
    
    if (indexPath == tmpPath) {
        
        [cell setHidden:YES];
    }
}


#pragma mark - 是否隐藏治疗选择
- (void)setIsTreated:(BOOL)isTreated {
    
    _isTreated = isTreated;
    
    // 获取要隐藏item的位置
    NSIndexPath *tmpPath = [NSIndexPath indexPathForRow:0 inSection:4];
    if (isTreated) {
      
        [[self.tableView cellForRowAtIndexPath:tmpPath] setHidden:NO];
    }else{
        
        [[self.tableView cellForRowAtIndexPath:tmpPath] setHidden:YES];
    }
}


#pragma mark - 搭建界面
- (void)xhhSetupSubviews {
    
     CGFloat margin = 12;
    CGFloat marginTop = 9;
    /*------------------typeLabel------------------*/
    UILabel *typeLabel = [[UILabel alloc] init];
    typeLabel.text = @"疾病类型：肿瘤疾病";
    typeLabel.font = [UIFont systemFontOfSize:14];
    typeLabel.textColor = [UIColor XHH_colorWithHex:0x525252];
    [self.view addSubview:typeLabel];
    
    [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(margin);
        make.top.equalTo(self.view).offset(marginTop + 64);
        
    }];
    
    
    /*------------------tableview------------------*/
    self.view.backgroundColor = [UIColor colorWithRed:0.94 green:0.94 blue:0.96 alpha:1.00];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    
    self.tableView = tableView;
    
    [self.view addSubview:tableView];
    
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.scrollEnabled = NO;
    
    tableView.rowHeight = 44;
    
    [tableView registerClass:[DHArrowTableViewCell class] forCellReuseIdentifier:arrowCellID];
    [tableView registerClass:[DHSelectTableViewCell class] forCellReuseIdentifier:selectCellID];
    
    
   
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(margin);
        make.right.equalTo(self.view).offset(-margin);

        make.top.equalTo(typeLabel.mas_bottom).offset(marginTop);
        make.bottom.equalTo(self.view).offset(margin*3);
    }];
    
    /*------------------就诊申请------------------*/
    UIButton *applyBtn = [[UIButton alloc] init];
    [applyBtn setTitle:@"就诊申请" forState:UIControlStateNormal];
    [applyBtn setBackgroundColor:[UIColor globalColor]];
    [applyBtn addTarget:self action:@selector(applyForDoctorWithData:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:applyBtn];
    
    
    [applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view).offset(margin);
        make.right.equalTo(self.view).offset(-margin);
        make.bottom.equalTo(self.view).offset(-margin);
//        make.height.mas_equalTo(50);
    }];
    
    
    /*------------------医生图标------------------*/
    UIImageView *doctorPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"doctorCount"]];
    
    [self.view addSubview: doctorPic];
    
    [doctorPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(applyBtn.mas_top).offset(-margin);
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    [doctorPic layoutIfNeeded];
    
    
    /*------------------匹配结果------------------*/
    UILabel *countLabel = [[UILabel alloc] init];
    countLabel.text = @"位";
    countLabel.font = [UIFont systemFontOfSize:14];
    countLabel.textColor = [UIColor globalColor];
    [self.view addSubview:countLabel];
    
    
    UILabel *doctorCount = [[UILabel alloc] init];
    doctorCount.text = @"100";
    doctorCount.font = [UIFont systemFontOfSize:24];
    doctorCount.textColor = [UIColor globalColor];
    [self.view addSubview:doctorCount];
    
    
    
    UILabel *textLabel = [[UILabel alloc] init];
    textLabel.text = @"重诊所为您匹配到";
    textLabel.font = [UIFont systemFontOfSize:13];
    textLabel.textColor = [UIColor XHH_colorWithHex:0xbfbfbf];
    [self.view addSubview:textLabel];
    
    
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(doctorPic);
        make.bottom.equalTo(doctorPic.mas_top).offset(-margin);
    }];
    
    [doctorCount mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.baseline.equalTo(countLabel);
        make.right.equalTo(countLabel.mas_left).offset(-margin);
    }];
    
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(countLabel.mas_top).offset(-margin);
        
    }];
    
    
    
    
    
    
    
//    //疾病种类
//    UILabel *diseaseType = [[UILabel alloc] init];
//    
//    //用户信息
//    UILabel *userInfo = [[UILabel alloc] init];
//    
//    //疾病细分
//    UILabel *diseaseSub = [[UILabel alloc] init];
//    
//    //并发症
//    UILabel *complications = [[UILabel alloc] init];
    
    
    //是否确诊
    
    
    
    //是否接受过治疗
    
    //治疗方式
    
    //匹配的医生数量
    
    //就诊申请
}

#pragma mark - 响应事件
//就诊申请
- (void)applyForDoctorWithData:(NSString *)data {
    
//    UIViewController *vc = [[UIViewController alloc] init];
    
    DHDoctorApplyViewController *doctorApplyVC = [[DHDoctorApplyViewController alloc] init];
    
    [self.navigationController pushViewController:doctorApplyVC animated:YES];
    
    
}

- (void)dealloc {
    
    NSLog(@"%s",__func__);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
